package com.example.conexion;




import android.content.Context;

import android.database.ContentObserver;
import android.media.AudioManager;
import android.os.Handler;

import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;



public class SettingsContentObserver extends ContentObserver {
    int previousVolume;
    Context context;

    private Messenger servicio; 
    

    public SettingsContentObserver(Context c, Handler handler) {
        super(handler);
        context=c;

        AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        previousVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
    }

    @Override
    public boolean deliverSelfNotifications() {
        return super.deliverSelfNotifications();
    }

    @Override
    public void onChange(boolean selfChange) {
    	 
        super.onChange(selfChange);

        AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);

        int delta=previousVolume-currentVolume;

        if(delta>0)
        {
          //  Logger.d("!");
            previousVolume=currentVolume;
        }
        else if(delta<0)
        {
           // Logger.d("!");
            previousVolume=currentVolume;
        }
        Message msg = new Message();
		msg.what =2;
		
		try {
			servicio.send(msg);
		} catch (RemoteException e) {
			//Si queremos avisar de algún error, aquí lo ponemos
		}
    }

	

	
}